package br.com.pb.bymychef.persistencia.bean;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name="tb_usuario")
@SequenceGenerator(name = "S_TB_USUARIO", sequenceName = "S_TB_USUARIO", initialValue = 0, allocationSize = 1)
public class Usuario implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "S_TB_USUARIO")
    @Column(name = "idUsuario")
    private Long idUsuario;
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="idPerfil", nullable=true)
    @JoinTable(name="tb_usuario")
    private Perfil perfil;
    @Column(name="idFacebook", nullable=true, unique=true)
    private Long idFacebook;
    @Column(name="login", length=50, nullable=true)
    private String login;
    @Column(name="email", length=80, nullable=true)
    private String email;
    @Column(name="senha", length=20, nullable=true)
    private String senha;
    @Temporal(TemporalType.DATE)
    @Column(name="dataNascimento", nullable=true)
    private Date dataNascmento;
    
    
    public Long getIdUsuario() {
        return idUsuario;
    }
    public Perfil getPerfil() {
        return perfil;
    }
    public void setPerfil(Perfil perfil) {
        this.perfil = perfil;
    }
    public Long getIdFacebook() {
        return idFacebook;
    }
    public void setIdFacebook(Long idFacebook) {
        this.idFacebook = idFacebook;
    }
    public String getLogin() {
        return login;
    }
    public void setLogin(String login) {
        this.login = login;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getSenha() {
        return senha;
    }
    public void setSenha(String senha) {
        this.senha = senha;
    }
    public Date getDataNascmento() {
        return dataNascmento;
    }
    public void setDataNascmento(Date dataNascmento) {
        this.dataNascmento = dataNascmento;
    }
    
    @Override
    public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result
		+ ((idUsuario == null) ? 0 : idUsuario.hashCode());
	return result;
    }
    @Override
    public boolean equals(Object obj) {
	if (this == obj)
	    return true;
	if (obj == null)
	    return false;
	if (getClass() != obj.getClass())
	    return false;
	Usuario other = (Usuario) obj;
	if (idUsuario == null) {
	    if (other.idUsuario != null)
		return false;
	} else if (!idUsuario.equals(other.idUsuario))
	    return false;
	return true;
    }
    
}
